clear all
set more off
tempfile temp

/*

This dofile uses data from Truth and Reconciliation Comission to calculate the number of violent events by year-district cells.

Here we consider violence only from 80s.

District code is harmonized to match the 1993 version. See ubigeo dofiles in the "ubigeo" directory within dofiles.

Outcome: number of events (Army only) by district-year

*/

** PATHS
local working ../working
local ubigeo ../ubigeo

** DATA
use `working'/actos_est_new

*keep if inlist(idtipoac,"LDS","MAE","MAT","MEF")

local best = 2001
gen dd = substr(ubidist,-2,2)
gen ubigeo`best' = ubidist
replace ubigeo`best' = substr(ubigeona,1,6) if dd == "00"
destring ubigeo`best', replace

drop _merge
merge m:1 ubigeo`best' using `ubigeo'/ubigeo`best'to1993
drop ubigeo`best'
drop if _merge == 2
drop if _merge == 1
drop _merge

gen year = ano
gen month = year(fechamed)

gen events = 1
gen events_fatal = inlist(idtipoac,"LDS","MAE","MAT","MEF")
gen events_nonfatal = events - events_fatal

gen terrorists = e00 + e01 + e02
gen government = estado

gen terrorists_fatal = terrorists if events_fatal == 1
gen terrorists_nonfatal = terrorists if events_nonfatal == 1

gen government_fatal = government if events_fatal == 1
gen government_nonfatal = government if events_nonfatal == 1

keep if government == 1
keep if year <= 1989

collapse (sum) events*, by(ubigeo1993 year) // so far without distinguishing perpetrator

rename ubigeo1993 ubigeonac1993
rename year yearviolence

** SAVE
save `working'/violenceA80, replace
